﻿using System;
using System.Runtime.InteropServices;
using System.Text;

namespace UtilZ.Dotnet.Ex.Base
{
    /// <summary>
    /// Marshal扩展类
    /// </summary>
    public unsafe static class MarshalEx
    {

        /// <summary>
        /// 将指定位置byte[]的数据拷贝到char[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcCount">字符对应的字节数</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destCount">要拷贝的目标数据长度</param>
        /// <param name="encoding">字符集编码</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, int srcCount, char[] destBuffer, int destStartIndex, int destCount, Encoding encoding)
        {
            fixed (byte* srcP = srcBuffer)
            {
                fixed (char* dstP = destBuffer)
                {
                    //int charCount = encoding.GetCharCount(srcBuffer, srcStartIndex, srcCount);
                    encoding.GetChars(srcP + srcStartIndex, srcCount, dstP + destStartIndex, destCount);
                }
            }
        }

        /// <summary>
        /// 将char[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcCount">要拷贝的原数据长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="encoding">字符集编码</param>
        public static void Copy(char[] srcBuffer, int srcStartIndex, int srcCount, byte[] destBuffer, int destStartIndex, Encoding encoding)
        {
            fixed (char* srcP = srcBuffer)
            {
                fixed (byte* dstP = destBuffer)
                {
                    int byteCount = encoding.GetByteCount(srcBuffer, srcStartIndex, srcCount);
                    encoding.GetBytes(srcP + srcStartIndex, srcCount, dstP + destStartIndex, byteCount);
                }
            }
        }



#if CORE6_P

        #region byte[]数组拷贝到short[]、int[]、long[]、float[]、double[]等数组


        /// <summary>
        /// 将指定位置byte[]的数据拷贝到short[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destCount">要拷贝的目标数据长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, short[] destBuffer, int destStartIndex, int destCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                fixed (short* desPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, desPtr, new nuint((ulong)(destCount * sizeof(short))));
                }
            }
        }

        /// <summary>
        /// 将指定位置byte[]的数据拷贝到short[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destByteCount">要拷贝的目标数据字节长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, short[] destBuffer, int destStartIndex, nuint destByteCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                fixed (short* desPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, desPtr, destByteCount);
                }
            }
        }



        /// <summary>
        /// 将指定位置byte[]的数据拷贝到int[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destCount">要拷贝的目标数据长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, int[] destBuffer, int destStartIndex, int destCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                fixed (int* desPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, desPtr, new nuint((ulong)(destCount * sizeof(int))));
                }
            }
        }

        /// <summary>
        /// 将指定位置byte[]的数据拷贝到int[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destByteCount">要拷贝的目标数据字节长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, int[] destBuffer, int destStartIndex, nuint destByteCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                fixed (int* desPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, desPtr, destByteCount);
                }
            }
        }





        /// <summary>
        /// 将指定位置byte[]的数据拷贝到long[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destCount">要拷贝的目标数据长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, long[] destBuffer, int destStartIndex, int destCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                fixed (long* desPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, desPtr, new nuint((ulong)(destCount * sizeof(long))));
                }
            }
        }

        /// <summary>
        /// 将指定位置byte[]的数据拷贝到long[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destByteCount">要拷贝的目标数据字节长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, long[] destBuffer, int destStartIndex, nuint destByteCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                fixed (long* desPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, desPtr, destByteCount);
                }
            }
        }





        /// <summary>
        /// 将指定位置byte[]的数据拷贝到float[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destCount">要拷贝的目标数据长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, float[] destBuffer, int destStartIndex, int destCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                fixed (float* desPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, desPtr, new nuint((ulong)(destCount * sizeof(float))));
                }
            }
        }

        /// <summary>
        /// 将指定位置byte[]的数据拷贝到float[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destByteCount">要拷贝的目标数据字节长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, float[] destBuffer, int destStartIndex, nuint destByteCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                fixed (float* desPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, desPtr, destByteCount);
                }
            }
        }






        /// <summary>
        /// 将指定位置byte[]的数据拷贝到double[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destCount">要拷贝的目标数据长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, double[] destBuffer, int destStartIndex, int destCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                fixed (double* desPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, desPtr, new nuint((ulong)(destCount * sizeof(double))));
                }
            }
        }

        /// <summary>
        /// 将指定位置byte[]的数据拷贝到double[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destByteCount">要拷贝的目标数据字节长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, double[] destBuffer, int destStartIndex, nuint destByteCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                fixed (double* desPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, desPtr, destByteCount);
                }
            }
        }





        /// <summary>
        /// 将指定位置byte[]的数据拷贝到指针指向的结构体中.
        /// 注:结构体类型,需要指定StructLayout(LayoutKind.Explicit, Size = x)
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destPtr">结构体针指</param>
        /// <param name="destSize">结构体大小</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, void* destPtr, int destSize)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                NativeMemory.Copy(srcPtr + srcStartIndex, destPtr, new nuint((ulong)destSize));
            }
        }

        /// <summary>
        /// 将指定位置byte[]的数据拷贝到指针指向的结构体中.
        /// 注:结构体类型,需要指定StructLayout(LayoutKind.Explicit, Size = x)
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destPtr">结构体针指</param>
        /// <param name="destByteCount">要拷贝的目标数据字节长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, void* destPtr, nuint destByteCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                NativeMemory.Copy(srcPtr + srcStartIndex, destPtr, destByteCount);
            }
        }

        #endregion



        #region short[]、int[]、long[]、float[]、double[]等数组拷贝到byte[]数组

        /// <summary>
        /// 将short[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcCount">要拷贝的原数据长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(short[] srcBuffer, int srcStartIndex, int srcCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (short* srcPtr = srcBuffer)
            {
                fixed (byte* destPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, destPtr + destStartIndex, new nuint((ulong)(sizeof(short) * srcCount)));
                }
            }
        }

        /// <summary>
        /// 将short[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcByteCount">要拷贝的原数据字节长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(short[] srcBuffer, int srcStartIndex, nuint srcByteCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (short* srcPtr = srcBuffer)
            {
                fixed (byte* destPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, destPtr + destStartIndex, srcByteCount);
                }
            }
        }



        /// <summary>
        /// 将int[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcCount">要拷贝的原数据长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(int[] srcBuffer, int srcStartIndex, int srcCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (int* srcPtr = srcBuffer)
            {
                fixed (byte* destPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, destPtr + destStartIndex, new nuint((ulong)(sizeof(int) * srcCount)));
                }
            }
        }

        /// <summary>
        /// 将int[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcByteCount">要拷贝的原数据字节长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(int[] srcBuffer, int srcStartIndex, nuint srcByteCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (int* srcPtr = srcBuffer)
            {
                fixed (byte* destPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, destPtr + destStartIndex, srcByteCount);
                }
            }
        }



        /// <summary>
        /// 将long[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcCount">要拷贝的原数据长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(long[] srcBuffer, int srcStartIndex, int srcCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (long* srcPtr = srcBuffer)
            {
                fixed (byte* destPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, destPtr + destStartIndex, new nuint((ulong)(sizeof(long) * srcCount)));
                }
            }
        }

        /// <summary>
        /// 将long[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcByteCount">要拷贝的原数据字节长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(long[] srcBuffer, int srcStartIndex, nuint srcByteCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (long* srcPtr = srcBuffer)
            {
                fixed (byte* destPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, destPtr + destStartIndex, srcByteCount);
                }
            }
        }




        /// <summary>
        /// 将float[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcCount">要拷贝的原数据长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(float[] srcBuffer, int srcStartIndex, int srcCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (float* srcPtr = srcBuffer)
            {
                fixed (byte* destPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, destPtr + destStartIndex, new nuint((ulong)(sizeof(float) * srcCount)));
                }
            }
        }

        /// <summary>
        /// 将float[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcByteCount">要拷贝的原数据字节长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(float[] srcBuffer, int srcStartIndex, nuint srcByteCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (float* srcPtr = srcBuffer)
            {
                fixed (byte* destPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, destPtr + destStartIndex, srcByteCount);
                }
            }
        }




        /// <summary>
        /// 将double[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcCount">要拷贝的原数据长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(double[] srcBuffer, int srcStartIndex, int srcCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (double* srcPtr = srcBuffer)
            {
                fixed (byte* destPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, destPtr + destStartIndex, new nuint((ulong)(sizeof(double) * srcCount)));
                }
            }
        }

        /// <summary>
        /// 将double[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcByteCount">要拷贝的原数据字节长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(double[] srcBuffer, int srcStartIndex, nuint srcByteCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (double* srcPtr = srcBuffer)
            {
                fixed (byte* destPtr = destBuffer)
                {
                    NativeMemory.Copy(srcPtr + srcStartIndex, destPtr + destStartIndex, srcByteCount);
                }
            }
        }



        /// <summary>
        /// 将指针指向的结构体拷贝到byte[]指定位置.
        /// 注:结构体类型,需要指定StructLayout(LayoutKind.Explicit, Size = x)
        /// </summary>
        /// <param name="srcP">结构体针指</param>
        /// <param name="srcSize">结构体大小</param>
        /// <param name="destBuffer">目标buffer</param>
        /// <param name="destStartIndex">目标buffer中的起始位置</param>
        public static void Copy(void* srcP, int srcSize, byte[] destBuffer, int destStartIndex)
        {
            fixed (byte* destPtr = destBuffer)
            {
                NativeMemory.Copy(srcP, destPtr + destStartIndex, new nuint((ulong)srcSize));
            }
        }

        /// <summary>
        /// 将指针指向的结构体拷贝到byte[]指定位置.
        /// 注:结构体类型,需要指定StructLayout(LayoutKind.Explicit, Size = x)
        /// </summary>
        /// <param name="srcP">结构体针指</param>
        /// <param name="srcByteCount">结构体字节大小度</param>
        /// <param name="destBuffer">目标buffer</param>
        /// <param name="destStartIndex">目标buffer中的起始位置</param>
        public static void Copy(void* srcP, nuint srcByteCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (byte* destPtr = destBuffer)
            {
                NativeMemory.Copy(srcP, destPtr + destStartIndex, srcByteCount);
            }
        }

        #endregion



        #region 指针拷贝到指针中

        /// <summary>
        /// 从源指针地址拷贝数据到目标指针地址
        /// </summary>
        /// <param name="srcPtr">源指针地址</param>
        /// <param name="destPtr">目标指针地址</param>
        /// <param name="destByteSize">目标指针地址指向空间字节大小</param>
        public static void Copy(void* srcPtr, void* destPtr, long destByteSize)
        {
            NativeMemory.Copy(srcPtr, destPtr, new nuint((ulong)destByteSize));
        }

        /// <summary>
        /// 从源指针地址拷贝数据到目标指针地址
        /// </summary>
        /// <param name="srcPtr">源指针地址</param>
        /// <param name="destPtr">目标指针地址</param>
        /// <param name="destByteSize">目标指针地址指向空间字节大小</param>
        public static void Copy(void* srcPtr, void* destPtr, nuint destByteSize)
        {
            NativeMemory.Copy(srcPtr, destPtr, destByteSize);
        }



        /// <summary>
        /// 从源指针地址拷贝数据到目标指针地址
        /// </summary>
        /// <param name="srcPtr">源指针地址</param>
        /// <param name="destPtr">目标指针地址</param>
        /// <param name="destByteSize">目标指针地址指向空间字节大小</param>
        public static void Copy(IntPtr srcPtr, IntPtr destPtr, long destByteSize)
        {
            NativeMemory.Copy((void*)srcPtr, (void*)destPtr, new nuint((ulong)destByteSize));
        }

        /// <summary>
        /// 从源指针地址拷贝数据到目标指针地址
        /// </summary>
        /// <param name="srcPtr">源指针地址</param>
        /// <param name="destPtr">目标指针地址</param>
        /// <param name="destByteSize">目标指针地址指向空间字节大小</param>
        public static void Copy(IntPtr srcPtr, IntPtr destPtr, nuint destByteSize)
        {
            NativeMemory.Copy((void*)srcPtr, (void*)destPtr, destByteSize);
        }

        #endregion



        #region 指针数据拷贝到short[]、int[]、long[]、float[]、double[]等数组

        /// <summary>
        /// byte指针数据拷贝到byte[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">byte数据长度</param>
        /// <returns>结果数据</returns>
        public static byte[] PtrToArray(byte* dataPtr, int length)
        {
            byte[] result = new byte[length];
            fixed (byte* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(byte))));
            }
            return result;
        }

        /// <summary>
        /// byte指针数据拷贝到byte[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">byte数据长度</param>
        public static void PtrToArray(byte* dataPtr, byte[] result, int length)
        {
            fixed (byte* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(byte))));
            }
        }

        /// <summary>
        /// byte指针数据拷贝到byte[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="byteLength">结果数据字节长度</param>
        public static void PtrToArray(byte* dataPtr, byte[] result, nuint byteLength)
        {
            fixed (byte* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, byteLength);
            }
        }




        /// <summary>
        /// sbyte指针数据拷贝到sbyte[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">sbyte数据长度</param>
        /// <returns>结果数据</returns>
        public static sbyte[] PtrToArray(sbyte* dataPtr, int length)
        {
            sbyte[] result = new sbyte[length];
            fixed (sbyte* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(sbyte))));
            }
            return result;
        }

        /// <summary>
        /// sbyte指针数据拷贝到sbyte[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">sbyte数据长度</param>
        public static void PtrToArray(sbyte* dataPtr, sbyte[] result, int length)
        {
            fixed (sbyte* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(sbyte))));
            }
        }

        /// <summary>
        /// sbyte指针数据拷贝到sbyte[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="byteLength">结果数据字节长度</param>
        public static void PtrToArray(sbyte* dataPtr, sbyte[] result, nuint byteLength)
        {
            fixed (sbyte* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, byteLength);
            }
        }





        /// <summary>
        /// short指针数据拷贝到short[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">short数据长度</param>
        /// <returns>结果数据</returns>
        public static short[] PtrToArray(short* dataPtr, int length)
        {
            short[] result = new short[length];
            fixed (short* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(short))));
            }
            return result;
        }

        /// <summary>
        /// short指针数据拷贝到short[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">short数据长度</param>
        public static void PtrToArray(short* dataPtr, short[] result, int length)
        {
            fixed (short* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(short))));
            }
        }

        /// <summary>
        /// short指针数据拷贝到short[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="byteLength">结果数据字节长度</param>
        public static void PtrToArray(short* dataPtr, short[] result, nuint byteLength)
        {
            fixed (short* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, byteLength);
            }
        }




        /// <summary>
        /// ushort指针数据拷贝到ushort[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">ushort数据长度</param>
        /// <returns>结果数据</returns>
        public static ushort[] PtrToArray(ushort* dataPtr, int length)
        {
            ushort[] result = new ushort[length];
            fixed (ushort* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(ushort))));
            }
            return result;
        }

        /// <summary>
        /// ushort指针数据拷贝到ushort[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">ushort数据长度</param>
        public static void PtrToArray(ushort* dataPtr, ushort[] result, int length)
        {
            fixed (ushort* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(ushort))));
            }
        }

        /// <summary>
        /// ushort指针数据拷贝到ushort[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="byteLength">结果数据字节长度</param>
        public static void PtrToArray(ushort* dataPtr, ushort[] result, nuint byteLength)
        {
            fixed (ushort* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, byteLength);
            }
        }





        /// <summary>
        /// int指针数据拷贝到int[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">int数据长度</param>
        /// <returns>结果数据</returns>
        public static int[] PtrToArray(int* dataPtr, int length)
        {
            int[] result = new int[length];
            fixed (int* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(int))));
            }
            return result;
        }

        /// <summary>
        /// int指针数据拷贝到int[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">int数据长度</param>
        public static void PtrToArray(int* dataPtr, int[] result, int length)
        {
            fixed (int* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(int))));
            }
        }

        /// <summary>
        /// int指针数据拷贝到int[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="byteLength">结果数据字节长度</param>
        public static void PtrToArray(int* dataPtr, int[] result, nuint byteLength)
        {
            fixed (int* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, byteLength);
            }
        }





        /// <summary>
        /// uint指针数据拷贝到uint[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">uint数据长度</param>
        /// <returns>结果数据</returns>
        public static uint[] PtrToArray(uint* dataPtr, uint length)
        {
            uint[] result = new uint[length];
            fixed (uint* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(uint))));
            }
            return result;
        }

        /// <summary>
        /// uint指针数据拷贝到uint[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">uint数据长度</param>
        public static void PtrToArray(uint* dataPtr, uint[] result, uint length)
        {
            fixed (uint* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(uint))));
            }
        }

        /// <summary>
        /// uint指针数据拷贝到uint[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="byteLength">结果数据字节长度</param>
        public static void PtrToArray(uint* dataPtr, uint[] result, nuint byteLength)
        {
            fixed (uint* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, byteLength);
            }
        }






        /// <summary>
        /// long指针数据拷贝到long[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">long数据长度</param>
        /// <returns>结果数据</returns>
        public static long[] PtrToArray(long* dataPtr, long length)
        {
            long[] result = new long[length];
            fixed (long* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(long))));
            }
            return result;
        }

        /// <summary>
        /// long指针数据拷贝到long[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">long数据长度</param>
        public static void PtrToArray(long* dataPtr, long[] result, long length)
        {
            fixed (long* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(long))));
            }
        }

        /// <summary>
        /// long指针数据拷贝到long[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="byteLength">结果数据字节长度</param>
        public static void PtrToArray(long* dataPtr, long[] result, nuint byteLength)
        {
            fixed (long* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, byteLength);
            }
        }





        /// <summary>
        /// ulong指针数据拷贝到ulong[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">ulong数据长度</param>
        /// <returns>结果数据</returns>
        public static ulong[] PtrToArray(ulong* dataPtr, ulong length)
        {
            ulong[] result = new ulong[length];
            fixed (ulong* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(ulong))));
            }
            return result;
        }

        /// <summary>
        /// ulong指针数据拷贝到ulong[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">ulong数据长度</param>
        public static void PtrToArray(ulong* dataPtr, ulong[] result, ulong length)
        {
            fixed (ulong* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(ulong))));
            }
        }

        /// <summary>
        /// ulong指针数据拷贝到ulong[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="byteLength">结果数据字节长度</param>
        public static void PtrToArray(ulong* dataPtr, ulong[] result, nuint byteLength)
        {
            fixed (ulong* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, byteLength);
            }
        }





        /// <summary>
        /// float指针数据拷贝到float[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">float数据长度</param>
        /// <returns>结果数据</returns>
        public static float[] PtrToArray(float* dataPtr, int length)
        {
            float[] result = new float[length];
            fixed (float* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(float))));
            }
            return result;
        }

        /// <summary>
        /// float指针数据拷贝到float[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">float数据长度</param>
        public static void PtrToArray(float* dataPtr, float[] result, int length)
        {
            fixed (float* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(float))));
            }
        }

        /// <summary>
        /// float指针数据拷贝到float[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="byteLength">结果数据字节长度</param>
        public static void PtrToArray(float* dataPtr, float[] result, nuint byteLength)
        {
            fixed (float* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, byteLength);
            }
        }





        /// <summary>
        /// double指针数据拷贝到double[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">double数据长度</param>
        /// <returns>结果数据</returns>
        public static double[] PtrToArray(double* dataPtr, int length)
        {
            double[] result = new double[length];
            fixed (double* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(double))));
            }
            return result;
        }

        /// <summary>
        /// double指针数据拷贝到double[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">double数据长度</param>
        public static void PtrToArray(double* dataPtr, double[] result, int length)
        {
            fixed (double* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, new nuint((ulong)(length * sizeof(double))));
            }
        }

        /// <summary>
        /// double指针数据拷贝到double[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="byteLength">结果数据字节长度</param>
        public static void PtrToArray(double* dataPtr, double[] result, nuint byteLength)
        {
            fixed (double* destPtr = result)
            {
                NativeMemory.Copy(dataPtr, destPtr, byteLength);
            }
        }


        #endregion


#else

        #region byte[]数组拷贝到short[]、int[]、long[]、float[]、double[]等数组

        /// <summary>
        /// 将指定位置byte[]的数据拷贝到short[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destCount">要拷贝的目标数据长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, short[] destBuffer, int destStartIndex, int destCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                IntPtr srcPtr2 = (IntPtr)((short*)(srcPtr + srcStartIndex));
                Marshal.Copy(srcPtr2, destBuffer, destStartIndex, destCount);
            }
        }

        /// <summary>
        /// 将指定位置byte[]的数据拷贝到int[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destCount">要拷贝的目标数据长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, int[] destBuffer, int destStartIndex, int destCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                IntPtr srcPtr2 = (IntPtr)((int*)(srcPtr + srcStartIndex));
                Marshal.Copy(srcPtr2, destBuffer, destStartIndex, destCount);
            }
        }

        /// <summary>
        /// 将指定位置byte[]的数据拷贝到long[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destCount">要拷贝的目标数据长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, long[] destBuffer, int destStartIndex, int destCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                IntPtr srcPtr2 = (IntPtr)((long*)(srcPtr + srcStartIndex));
                Marshal.Copy(srcPtr2, destBuffer, destStartIndex, destCount);
            }
        }

        /// <summary>
        /// 将指定位置byte[]的数据拷贝到float[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destCount">要拷贝的目标数据长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, float[] destBuffer, int destStartIndex, int destCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                IntPtr srcPtr2 = (IntPtr)((float*)(srcPtr + srcStartIndex));
                Marshal.Copy(srcPtr2, destBuffer, destStartIndex, destCount);
            }
        }

        /// <summary>
        /// 将指定位置byte[]的数据拷贝到double[]数组中.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        /// <param name="destCount">要拷贝的目标数据长度</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, double[] destBuffer, int destStartIndex, int destCount)
        {
            fixed (byte* srcPtr = srcBuffer)
            {
                IntPtr srcPtr2 = (IntPtr)((double*)(srcPtr + srcStartIndex));
                Marshal.Copy(srcPtr2, destBuffer, destStartIndex, destCount);
            }
        }

        /// <summary>
        /// 将指定位置byte[]的数据拷贝到指针指向的结构体中.
        /// 注:结构体类型,需要指定StructLayout(LayoutKind.Explicit, Size = x)
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="destPtr">结构体针指</param>
        /// <param name="destSize">结构体大小</param>
        public static void Copy(byte[] srcBuffer, int srcStartIndex, void* destPtr, int destSize)
        {
            Marshal.Copy(srcBuffer, srcStartIndex, (IntPtr)(destPtr), destSize);
        }

        #endregion



        #region short[]、int[]、long[]、float[]、double[]等数组拷贝到byte[]数组


        /// <summary>
        /// 将short[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcCount">要拷贝的原数据长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(short[] srcBuffer, int srcStartIndex, int srcCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (byte* destPtr = destBuffer)
            {
                IntPtr dstPtr2 = (IntPtr)((short*)(destPtr + destStartIndex));
                Marshal.Copy(srcBuffer, srcStartIndex, dstPtr2, srcCount);
            }
        }

        /// <summary>
        /// 将int[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcCount">要拷贝的原数据长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(int[] srcBuffer, int srcStartIndex, int srcCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (byte* destPtr = destBuffer)
            {
                IntPtr dstPtr2 = (IntPtr)((int*)(destPtr + destStartIndex));
                Marshal.Copy(srcBuffer, srcStartIndex, dstPtr2, srcCount);
            }
        }

        /// <summary>
        /// 将long[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcCount">要拷贝的原数据长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(long[] srcBuffer, int srcStartIndex, int srcCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (byte* destPtr = destBuffer)
            {
                IntPtr dstPtr2 = (IntPtr)((long*)(destPtr + destStartIndex));
                Marshal.Copy(srcBuffer, srcStartIndex, dstPtr2, srcCount);
            }
        }

        /// <summary>
        /// 将float[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcCount">要拷贝的原数据长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(float[] srcBuffer, int srcStartIndex, int srcCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (byte* destPtr = destBuffer)
            {
                IntPtr dstPtr2 = (IntPtr)((float*)(destPtr + destStartIndex));
                Marshal.Copy(srcBuffer, srcStartIndex, dstPtr2, srcCount);
            }
        }

        /// <summary>
        /// 将double[]数组指定位置描写长度的数据拷贝到byte[]数组中的指定位置.
        /// </summary>
        /// <param name="srcBuffer">数据原buffer</param>
        /// <param name="srcStartIndex">数据原buffer中的起始位置</param>
        /// <param name="srcCount">要拷贝的原数据长度</param>
        /// <param name="destBuffer">目标数组buffer</param>
        /// <param name="destStartIndex">目标数组buffer中的起始位置</param>
        public static void Copy(double[] srcBuffer, int srcStartIndex, int srcCount, byte[] destBuffer, int destStartIndex)
        {
            fixed (byte* destPtr = destBuffer)
            {
                IntPtr dstPtr2 = (IntPtr)((double*)(destPtr + destStartIndex));
                Marshal.Copy(srcBuffer, srcStartIndex, dstPtr2, srcCount);
            }
        }

        /// <summary>
        /// 将指针指向的结构体拷贝到byte[]指定位置.
        /// 注:结构体类型,需要指定StructLayout(LayoutKind.Explicit, Size = x)
        /// </summary>
        /// <param name="srcP">结构体针指</param>
        /// <param name="srcSize">结构体大小</param>
        /// <param name="destBuffer">目标buffer</param>
        /// <param name="destStartIndex">目标buffer中的起始位置</param>
        public static void Copy(void* srcP, int srcSize, byte[] destBuffer, int destStartIndex)
        {
            Marshal.Copy((IntPtr)(srcP), destBuffer, destStartIndex, srcSize);
        }

        #endregion



        #region 指针拷贝到指针中

        /// <summary>
        /// 从源指针地址拷贝数据到目标指针地址
        /// </summary>
        /// <param name="srcPtr">源指针地址</param>
        /// <param name="destPtr">目标指针地址</param>
        /// <param name="destByteSize">目标指针地址指向空间字节大小</param>
        public static void Copy(void* srcPtr, void* destPtr, long destByteSize)
        {
            NativeMemory.Copy(srcPtr, destPtr, (nuint)destByteSize);
        }

        /// <summary>
        /// 从源指针地址拷贝数据到目标指针地址
        /// </summary>
        /// <param name="srcPtr">源指针地址</param>
        /// <param name="destPtr">目标指针地址</param>
        /// <param name="destByteSize">目标指针地址指向空间字节大小</param>
        public static void Copy(IntPtr srcPtr, IntPtr destPtr, long destByteSize)
        {
            NativeMemory.Copy((void*)srcPtr, (void*)destPtr, (nuint)destByteSize);
        }

        #endregion



        #region 指针数据拷贝到short[]、int[]、long[]、float[]、double[]等数组

        /// <summary>
        /// byte指针数据拷贝到byte[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">byte数据长度</param>
        /// <returns>结果数据</returns>
        public static byte[] PtrToArray(byte* dataPtr, int length)
        {
            byte[] result = new byte[length];
            Marshal.Copy((IntPtr)dataPtr, result, 0, length);
            return result;
        }

        /// <summary>
        /// byte指针数据拷贝到byte[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">byte数据长度</param>
        public static void PtrToArray(byte* dataPtr, byte[] result, int length)
        {
            Marshal.Copy((IntPtr)dataPtr, result, 0, length);
        }



        /// <summary>
        /// short指针数据拷贝到short[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">short数据长度</param>
        /// <returns>结果数据</returns>
        public static short[] PtrToArray(short* dataPtr, int length)
        {
            short[] result = new short[length];
            Marshal.Copy((IntPtr)dataPtr, result, 0, length);
            return result;
        }

        /// <summary>
        /// short指针数据拷贝到short[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">short数据长度</param>
        public static void PtrToArray(short* dataPtr, short[] result, int length)
        {
            Marshal.Copy((IntPtr)dataPtr, result, 0, length);
        }



        /// <summary>
        /// int指针数据拷贝到int[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">int数据长度</param>
        /// <returns>结果数据</returns>
        public static int[] PtrToArray(int* dataPtr, int length)
        {
            int[] result = new int[length];
            Marshal.Copy((IntPtr)dataPtr, result, 0, length);
            return result;
        }

        /// <summary>
        /// int指针数据拷贝到int[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">int数据长度</param>
        public static void PtrToArray(int* dataPtr, int[] result, int length)
        {
            Marshal.Copy((IntPtr)dataPtr, result, 0, length);
        }




        /// <summary>
        /// long指针数据拷贝到long[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">long数据长度</param>
        /// <returns>结果数据</returns>
        public static long[] PtrToArray(long* dataPtr, int length)
        {
            long[] result = new long[length];
            Marshal.Copy((IntPtr)dataPtr, result, 0, length);
            return result;
        }

        /// <summary>
        /// long指针数据拷贝到long[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">long数据长度</param>
        public static void PtrToArray(long* dataPtr, long[] result, int length)
        {
            Marshal.Copy((IntPtr)dataPtr, result, 0, length);
        }





        /// <summary>
        /// float指针数据拷贝到float[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">float数据长度</param>
        /// <returns>结果数据</returns>
        public static float[] PtrToArray(float* dataPtr, int length)
        {
            float[] result = new float[length];
            Marshal.Copy((IntPtr)dataPtr, result, 0, length);
            return result;
        }

        /// <summary>
        /// float指针数据拷贝到float[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">float数据长度</param>
        public static void PtrToArray(float* dataPtr, float[] result, int length)
        {
            Marshal.Copy((IntPtr)dataPtr, result, 0, length);
        }



        /// <summary>
        /// double指针数据拷贝到double[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="length">double数据长度</param>
        /// <returns>结果数据</returns>
        public static double[] PtrToArray(double* dataPtr, int length)
        {
            double[] result = new double[length];
            Marshal.Copy((IntPtr)dataPtr, result, 0, length);
            return result;
        }

        /// <summary>
        /// double指针数据拷贝到double[]
        /// </summary>
        /// <param name="dataPtr">数据指针</param>
        /// <param name="result">结果数据</param>
        /// <param name="length">double数据长度</param>
        public static void PtrToArray(double* dataPtr, double[] result, int length)
        {
            Marshal.Copy((IntPtr)dataPtr, result, 0, length);
        }


        #endregion


#endif


    }
}
